package com.csdj.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.server.mapper.AdminRoleMapper;
import com.csdj.server.pojo.AdminRole;
import com.csdj.server.pojo.RespBean;
import com.csdj.server.service.IAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ZouLi
 * @since 2022-12-12
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {
    /**
     * 注入 AdminRoleMapper
     **/
    @Autowired(required = false)
    private AdminRoleMapper adminRoleMapper;

    @Override
    @Transactional
    public RespBean updateAdminRole(Integer aId, Integer[] rIds) {
        // 先删除
        int delete = adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId", aId));
        Integer result = adminRoleMapper.addRole(aId, rIds);
        if (result == rIds.length) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }
}
